<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>表白墙</title>

    <style>
        * {
            padding:0;
            margin:0;
            box-sizing: border-box;
        }

        .container {
            width: 800px;
            margin: 10px auto;
        }

        .container h2 {
            text-align: center;
            margin:30px 0px;
        }

        .row {
            height: 50px;
            display: flex;
            justify-content: center;
            margin-top: 5px;
            line-height: 50px;
        }
        .row span {
            height: 50px;
            width: 100px;
            line-height: 50px;
        }
        .row input {
            height: 50px;
            width: 300px;
            line-height: 50px;
        }
        .row button {
            width: 400px;
            height: 50px;
            /* margin:10px 0px; */
            color: black;
            background-color: aquamarine;
            border: none;
            border-radius: 10px;
        }

        /* 鼠标点击时的style */
        .row button:active {
            background-color: grey;
        }
    </style>
</head>
<body>
    <!-- 这是一个顶层容器,放其他元素 -->

    <div class="container">
        <h2>表白墙</h2>
        <div class="row">
            <span>谁</span>
            <input type="text" id="from">
        </div>
       
        <div class="row">
            <span>对谁</span>
            <input type="text" id="to">
        </div>
        <div class="row">
            <span>说什么</span>
            <input type="text" id="message">
        </div>
        <div class="row">
            <button>提交</button>
        </div>
    </div>
    <script>
        let container = document.querySelector('.container');
        let fromInput = document.querySelector('#from');
        let toInput = document.querySelector('#to');
        let messageInput = document.querySelector('#message');
        let button = document.querySelector('button');
        button.onclick = function() {
            //1.把用户输入的内容获取
            let from = fromInput.value;
            let to = toInput.value;
            let message = messageInput.value;
            if(from == '' || to == '' || message == '') {
                return;
            }

            //2.构造一个div,把这个div插入到 .container 的末尾
            let newDiv = document.createElement('div');
            newDiv.className = 'row';
            newDiv.innerHTML = from + "对" + to + "说: " +message;
            //3.把div挂在container里面
            container.appendChild(newDiv);
            //4.把之前的输入框内容进行清空
            fromInput.value = '';
            toInput.value = '';
            messageInput.value = '';
        }
    </script>
     
</body>
</html>